package com.komodo.island.gdx.dialog;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.actors.Button;
import com.badlogic.gdx.scenes.scene2d.actors.Image;
import com.komodo.island.gdx.Art;
import com.komodo.island.gdx.Input;
import com.komodo.island.gdx.KomodoIsland;
import com.komodo.island.gdx.Persistence;
import com.komodo.island.gdx.screen.GameScreen;
import com.komodo.island.gdx.screen.Screen;

public  class LoseDialog extends Dialog{

	Button retry;
	Button mainMenu;
	public Image bgImage;
	public Image text;
	
	Image newPiece;
	
	public Image siKomo;
	public Image score;
	
	public LoseDialog(float width, float height, boolean stretch, Screen screen, Texture texture,KomodoIsland komodoIsland) {
		super(width, height, stretch, screen,texture,komodoIsland);
		// TODO Auto-generated constructor stub
		ID = Input.DIALOG_LOSE;
	}
	@Override
	public void init() {
		// TODO Auto-generated method stub
		background = new Image(backgroundName, new TextureRegion(komodoIsland.menuTexture,480, 0, 480, 320));
		bgImage = new Image("bg", new TextureRegion(texture, 0, 0,
				351, 194));
		siKomo= new Image("komo", new TextureRegion(texture, 351+200+179, 0,
				100, 102));
		score= new Image("score", new TextureRegion(texture, 300, 194,
				47, 16));
		text = new Image ("text", new TextureRegion(texture,351,58*2, 181, 28));
		mainMenu = new Button("main menu", new TextureRegion(texture,351+200+97,71+28*2+64, 32, 32), new TextureRegion(texture,351+200+97+32,71+28*2+64, 32,
				32));
		newPiece= new Image("new piece", new TextureRegion(texture, 351,58*2+28,
				179, 71));	
//		help = new Button("help", new TextureRegion(texture,351+200+97,71+28*2+64+32, 32, 32), new TextureRegion(texture,351+200+97+32,71+28*2+64+32, 32,
//				32));
		
		retry = new Button("retry", new TextureRegion(texture,351+200,71+28*2+64+28, 32, 32), new TextureRegion(texture,351+200+32,71+28*2+64+28, 32,
				32));
		
	}

	@Override
	public void addElements() {
		// TODO Auto-generated method stub
		addActor(background);
		addActor(bgImage);
		addActor(score);
//		addActor(siKomo);
		addActor(text);
		addActor(retry);
		addActor(mainMenu);
		addActor(newPiece);
	}

	@Override
	public void setThePosition() {
		// TODO Auto-generated method stub
		bgImage.x = 240 -  351/2;
		bgImage.y = 160-194/2;
		
		score.x=  bgImage.x +32;
		score.y = bgImage.y + 5;
		
		 siKomo.x =bgImage.x + 28;
		 siKomo.y = bgImage.y + 194 - siKomo.height - 14;
		
		text.x = bgImage.x + 28 + bgImage.width / 3 - 10;
		text.y = bgImage.y + 64 * 2 + 14;
		
		retry.x = bgImage.x + 128 + 32 - 16;
		retry.y = bgImage.y + 96;
		
		mainMenu.x = retry.x + retry.width + 32;
		mainMenu.y = retry.y ;
		
		newPiece.x = 0;
		newPiece.y = 0;
		
	}

	@Override
	public void setTheListener() {
		// TODO Auto-generated method stub
		retry.clickListener = new Button.ClickListener() {

			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				if (Persistence.sound)
					komodoIsland.dialogSound.play(1);
				((GameScreen)screen ).retryGame();
			}
		};
		mainMenu.clickListener = new Button.ClickListener() {

			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				if (Persistence.sound)
					komodoIsland.dialogSound.play(1);
				((GameScreen)screen ).exitScreen();
			}
		};
	}
	@Override
	public void draw() {
		// TODO Auto-generated method stub
		super.draw();
		Art.drawString(getSpriteBatch(), ((GameScreen)screen).score+"",(int)( score.x + score.width + 1), (int)bgImage.y);
	}

	public void showNewPiece(){
		addActor(newPiece);
	}
	
	public void hideAllNotif(){
		removeActor(newPiece);
	}
}
